home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig10_02.jar / Ch10 / Fig10_02 / Cylindr1.cpp < prev    next >
C/C++ Source or Header  |  1997-10-28  |  693b  |  29 lines

  1. // Fig. 10.2: cylindr1.cpp
  2. // Member and friend function definitions for class Cylinder
  3. #include "cylindr1.h"
  4.  
  5. Cylinder::Cylinder( double h, double r, int x, int y )
  6.    : Circle( r, x, y )  // call base-class constructor
  7. { setHeight( h ); }
  8.  
  9. void Cylinder::setHeight( double h )
  10.    { height = h > 0 ? h : 0; }
  11.  
  12. double Cylinder::getHeight() { return height; }
  13.  
  14. double Cylinder::area() const
  15. {
  16.    // surface area of Cylinder
  17.    return 2 * Circle::area() +
  18.           2 * 3.14159 * getRadius() * height;
  19. }
  20.  
  21. double Cylinder::volume() const 
  22.    { return Circle::area() * height; }
  23.  
  24. void Cylinder::print() const
  25. {
  26.    Circle::print();
  27.    cout << "; Height = " << height;
  28. }
  29.